#include "../include/client.h"

int clientLs(int sockFd, char *ss){
    //把指令发给服务器，接收返回结果并打印
    FileInfo files[100]; //使用结构体接收服务器返回的文件属性
    int fileCnt = 0;
    char recvBuf[128] = {0};
    int dataLen = 0;

    send(sockFd, ss, 128, 0);

    int ret = recv(sockFd, &dataLen, 4, MSG_WAITALL);
    /* printf("ret = %d\n", ret); */
    ret = recv(sockFd, &fileCnt, dataLen, MSG_WAITALL);
    /* printf("ret = %d\n", ret); */
    printf("\nfileCnt = %d\n", fileCnt);

    for(int i = 0; i < fileCnt; ++i){
        memset(recvBuf, 0, sizeof(recvBuf));
        recv(sockFd, recvBuf, sizeof(files[i]), 0);
        memcpy(&files[i], recvBuf, sizeof(recvBuf));
    }

    printf("-- fileName             fileSize          fileType--\n");

    for(int i = 0; i < fileCnt; ++i){
        //打印目录下的文件信息
        printf(">> %-22s%-20ld%-2c\n",          
                files[i].fileName, files[i].fileSize, files[i].type);
    }
     return 1;
}
